package com.opennews.openplatform.myspringbootcore.util

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import java.time.LocalDateTime

class LocalDateTimeToUTCSerializer : StdSerializer<LocalDateTime>(LocalDateTime::class.java) {
    override fun serialize(
        value: LocalDateTime?,
        gen: JsonGenerator?,
        provider: SerializerProvider?,
    ) {
        if (value != null && gen != null) {
            val formatted = DateHelper.convertLocalDateTimeToUTCString(value)
            gen.writeString(formatted)
        }
    }
}